#ifndef __MBM_SOCKET_ADAPTER__
#define __MBM_SOCKET_ADAPTER__

#ifdef __cplusplus
extern "C"
{
#endif

#define  MBM_AF_INET     2     /* internetwork: UDP, TCP, etc. */

#define  MBM_SOCK_STREAM    1     /* stream socket */
#define  MBM_SOCK_DGRAM     2     /* datagram socket */
#define  MBM_SOCK_RAW       3     /* raw-protocol interface */

#define MBM_SOC_SUCCESS     (0)
#define MBM_SOC_FAIL        (-1)

typedef enum{
	MBM_SOC_ENOBUFS = 1     ,  
	MBM_SOC_ETIMEDOUT     ,  
	MBM_SOC_EISCONN       ,  
	MBM_SOC_EOPNOTSUPP    ,  
	MBM_SOC_ECONNABORTED  ,  
	MBM_SOC_EWOULDBLOCK   ,  
	MBM_SOC_ECONNREFUSED  ,  
	MBM_SOC_ECONNRESET    ,  
	MBM_SOC_ENOTCONN      ,  
	MBM_SOC_EALREADY      ,  
	MBM_SOC_EINVAL        ,  
	MBM_SOC_EMSGSIZE      ,  
	MBM_SOC_EPIPE         ,  
	MBM_SOC_EDESTADDRREQ  ,  
	MBM_SOC_ESHUTDOWN     ,  
	MBM_SOC_ENOPROTOOPT   ,  
	MBM_SOC_EHAVEOOB      ,  
	MBM_SOC_ENOMEM        ,  
	MBM_SOC_EADDRNOTAVAIL ,  
	MBM_SOC_EADDRINUSE    ,  
	MBM_SOC_EAFNOSUPPORT  ,  
	MBM_SOC_EINPROGRESS   ,  
	MBM_SOC_ELOWER        , /* lower layer (IP) error */
	MBM_SOC_ENOTSOCK      ,   /* Includes sockets which closed while blocked */
	MBM_SOC_EIEIO         ,/* bad input/output on Old Macdonald's farm :-) */
	MBM_SOC_UNKNOWN_ERRNO
}  MBM_SOC_ERRNO_E;

typedef enum{
	MBM_SO_RXDATA,      /* get count of bytes in sb_rcv */
	MBM_SO_TXDATA,      /* get count of bytes in sb_snd */
	MBM_SO_MYADDR,      /* return my IP address */
	MBM_SO_NBIO,        /* set socket into NON-blocking mode */
	MBM_SO_BIO,         /* set socket into blocking mode */
	MBM_SO_NONBLOCK,    /* set/get blocking mode via optval param */
	MBM_SO_CALLBACK,    /* set/get zero_copy callback routine */
	MBM_SO_OPT_MAX
} MBM_SOC_OPT_E;

typedef struct
{
	UInt8 ip[4];
	Int32 len;
	Int32 id;
} t_mbm_dns_ip;

typedef struct
{
	Int32 soc;
	Int32 msgId;
} t_mbm_sock_notify_msg;

typedef void (*mbm_dns_notify_fun)(UInt8* ip, Int32 ip_len, Int32 req_id);
typedef void (*mbm_socket_notify_fun)(Int32 soc, Int32 msgId);

/**
 * @name mbm_soc_send -discripe
 *
 * @param param1	-property	-discripe
 *
 * @return -discripe
 */
Int32 mbm_soc_send(Int32 s, Int8 *buf, Int32 len, Int32 flags);

/**
 * @name mbm_soc_recv -discripe
 *
 * @param param1	-property	-discripe
 *
 * @return -discripe
 */
Int32 mbm_soc_recv(Int32 s, Int8 * buf, Int32 len, Int32 flags);

/**
 * @name mbm_sock_close -discripe
 *
 * @param param1	-property	-discripe
 *
 * @return -discripe
 */
void mbm_sock_close(Int32 s);

/**
 * @name mbm_soc_errno -discripe
 *
 * @param param1	-property	-discripe
 *
 * @return -reference MBM_SOC_ERRNO_E
 */
Int32 mbm_soc_errno(Int32 s);

Int32 mbm_traslate_soc_errno(Int32 err);

/**
 * @name mbm_soc_connect -discripe
 *
 * @param param1	-property	-discripe
 *
 * @return -discripe
 */
Int32 mbm_soc_connect(Int32 socket, Int32 type, Int32 ipaddr, Int32 port);

/**
 * @name mbm_soc_socket -discripe
 *
 * @param param1	-property	-discripe
 *
 * @return -discripe
 */
Int32 mbm_soc_socket(Int32 domain, Int32 type, Int32 protocol);

/**
 * @name mbm_soc_gethostbyname -discripe
 *
 * @param param1	-property	-discripe
 *
 * @return -discripe
 */
Int32 mbm_soc_gethostbyname(Int32 req_id, ImpCStr domain_name, ImpStr addr, Int32* addr_len);

/**
 * @name mbm_soc_setsockopt -discripe
 *
 * @param option	-in	-reference MBM_SOC_OPT_E
 *
 * @return -discripe
 */
void mbm_soc_setsockopt(Int32 socket, Int32 option, Int8* pValue);
void mbm_set_socket_async(Int32 socket);

/**
 * @name mbm_fd_zero -discripe
 *
 * @param param1	-property	-discripe
 *
 * @return -discripe
 */
void mbm_fd_zero(void * fd_send);

/**
 * @name mbm_fd_set -discripe
 *
 * @param param1	-property	-discripe
 *
 * @return -discripe
 */
void mbm_fd_set(Int32 socket, void * fd_set);

/**
 * @name mbm_sock_select -discripe
 *
 * @param param1	-property	-discripe
 *
 * @return -discripe
 */
Int32 mbm_sock_select(void *in, void * out, void * ex, Int32 tv);

/**
 * @name mbm_fd_isset -discripe
 *
 * @param param1	-property	-discripe
 *
 * @return -discripe
 */
Int32 mbm_fd_isset(Int32 socket, void * set);

/**
 * @name mbm_reg_dns_notify_handle -discripe
 *
 * @param param1	-property	-discripe
 *
 * @return -discripe
 */
void mbm_reg_dns_notify_handle(mbm_dns_notify_fun cb);

/**
 * @name mbm_reg_socket_notify_handle -discripe
 *
 * @param param1	-property	-discripe
 *
 * @return -discripe
 */
void mbm_reg_socket_notify_handle(mbm_socket_notify_fun cb);


/**
 * @name MBM_SocNotifyHandle -discripe
 *
 * @param param1	-property	-discripe
 *
 * @return -discripe
 */
//void MBM_SocNotifyHandle(t_mbm_sock_notify_msg* msg);

/**
 * @name MBM_SocNotifyHandle -discripe
 *
 * @param param1	-property	-discripe
 *
 * @return -discripe
 */
void mbm_send_soc_notify_msg_to_network_thread(void* msg, UInt32 msg_size);
ImpBool mbm_send_soc_disconnect_msg_to_network_thread(void* inst, void* channel);

UInt32 mbm_network_select_task_create(void);
void mbm_network_select_task_delete(void);


UInt32 mbm_create_network_thread(void);
void mbm_network_thread_delete(void);

#ifdef __cplusplus
}
#endif

#endif/* __MBM_SOCKET_ADAPTER__  */
